<?php
require 'cls/base.php';

$tpl = new Template('t');
$tpl->setFile ( "main", "submit.html" );
$tpl->setBlock ( "main", "submit", "submits" );
$tpl->setBlock ( "main", "list", "lists" );
$tpl->setBlock ( "list", "con", "cons" );

$target = fget("target");

$db = conn();

if($target == "list"){
	$ac = fget("ac");
	$id = fget("id");
	if($ac == "del"){
		$sql_del = "delete from collect where id={$id}";
		$db->query($sql_del);
		$tpl->setVar("del_msg", "删除成功");
	}
	$sql = "select * from collect order by id desc";
	$rs=$db->query($sql);
	foreach($rs as $v){
		$tpl->setVar(array(
			"con_id" => $v['id'],
			"con_title" => $v['caption'],
			"con_content" => $v['content'],
			"con_link" => $v['links']
			));
		$tpl->parse("cons", "con", true);
	}
	$tpl->parse("main", "list", true);
}else{
	//----------------------添加数据
	if(pm() == "POST"){
		//获取提交数据
		$caption = addslashes(trim(fpost("caption")));
		$content = addslashes(trim(fpost("content")));
		$links = addslashes(trim(fpost("links")));
		$types = fpost("types");
		//入库
		$sql = "insert into collect (caption, content, links, types, subtime) values('{$caption}', '{$content}', '{$links}',{$types},now())";
		$rs=$db->query($sql);
		$db->close();
		$tpl->setVar("msg", "添加成功！");
	}
	$tpl->parse("main", "submit", true);
}
$tpl->p("main");
?>